package view;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;

/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class About extends JDialog implements KeyListener {
    private static final long serialVersionUID = 1L;
    private AbstractAction btnOnClickAction;
    private JEditorPane jEditorPane1;
    private JButton btnOk;

    public About(final JFrame parent) {
        initGUI();
        setFocusable(true);
        addKeyListener(this);
    }

    private void initGUI() {
        try {

            getContentPane().setLayout(null);
            getContentPane().setBackground(new java.awt.Color(255, 255, 255));
            this.setResizable(false);

            jEditorPane1 = new JEditorPane();
            getContentPane().add(jEditorPane1);
            jEditorPane1.setBounds(7, 12, 267, 129);
            jEditorPane1.setText("Ludo is a board game.\nYou are an alpha tester.");
            jEditorPane1.setEditable(false);

            btnOk = new JButton();
            getContentPane().add(btnOk);
            btnOk.setBounds(233, 141, 50, 21);
            btnOk.setMargin(new Insets(2, 2, 2, 2));
            btnOk.setAction(getBtnOnClickAction());
            btnOk.setText("OK");

            this.setSize(300, 200);
            this.setLocationRelativeTo(this.getParent());
            this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            this.setVisible(true);
            this.setTitle("About");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private AbstractAction getBtnOnClickAction() {
        if (btnOnClickAction == null) {
            btnOnClickAction = new AbstractAction("OK", null) {
                private static final long serialVersionUID = 1L;
                public void actionPerformed(final ActionEvent evt) {
                    dispose();
                }
            };
        }
        return btnOnClickAction;
    }

    @Override
    public final void keyPressed(final KeyEvent e) {
        Character c = e.getKeyChar();
        if (c.equals('\n')) {
            System.out.println("About issues");
            btnOk.doClick();
        }
    }

    @Override
    public void keyReleased(final KeyEvent e) { }

    @Override
    public void keyTyped(final KeyEvent e) { }
}
